using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Magiq.Delete;
using Magiq.Insert;
using Magiq.Update;

namespace Magiq {
  public static class Enumerable {
    public static IUpdate<T> Set<T, R>(this IEnumerable<T> enumerable, Expression<Func<T, R>> property, R value)
      where T : class {
      return new EnumerableUpdate<T>(enumerable).Set(property, value);
    }

    public static IUpdate<T> Set<T, R>(this IEnumerable<T> enumerable, Expression<Func<T, R>> property,
                                       Expression<Func<T, R>> value) where T : class {
      return new EnumerableUpdate<T>(enumerable).Set(property, value);
    }

    public static int Delete<T>(this IEnumerable<T> enumerable) where T : class {
      return new EnumerableDelete<T>(enumerable).Execute();
    }

    public static int Delete<T>(this IEnumerable<T> enumerable, Func<T, bool> where) where T : class {
      return enumerable.Where(where).Delete();
    }

    public static IEnumerableInsert<T> Insert<F, T>(this IEnumerable<F> enumerable, Expression<Func<F, T>> select)
      where F : class
      where T : class {
      return new EnumerableInsert<F, T>(enumerable, select);
    }
  }
}